import { Component } from 'react'
import styles from './index.less'

const worker = new Worker(new URL('./test.worker.js', import.meta.url));


export default class Remind extends Component {

  state = {
    data: [1]
  }

  componentDidMount() {
    const _this = this
    if (worker) {
      worker.onmessage = function (event) {
        console.log('revive', event.data)
        _this.setState({
          data: event.data
        })

      }
      worker.onerror = function (event) {
        console.log('error',)
      }
    }
  }

  handleClick = () => {
    worker.postMessage({ data: '333333' })
  }

  render() {
    return <div className={styles.testColor}>
      <button onClick={this.handleClick}>点击{this.state.data.length}</button>
    </div>
  }
}